package com.sixseven.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sixseven.bean.AnnAndComs;
import com.sixseven.bean.Announcement;
import com.sixseven.bean.Comment;
import com.sixseven.bean.Member;
import com.sixseven.mapper.AnnouncementMapper;
import com.sixseven.mapper.CommentMapper;
import com.sixseven.service.AnnouncementService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Belly
 * @version 1.1.0
 */
@Service
public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, Announcement> implements AnnouncementService {
    @Resource
    private CommentMapper commentMapper;
    @Override
    public Map<Integer, AnnAndComs> AnnouncementAndComments() {
        HashMap<Integer, AnnAndComs> annAndComsHashMap = new HashMap<>();
        List<Announcement> announcementList = this.list();
        for (Announcement announcement : announcementList) {
            annAndComsHashMap.put(announcement.getId(),
                    new AnnAndComs(announcement, commentMapper.selectList(
                            new LambdaQueryWrapper<Comment>()
                                    .eq(Comment::getAnnouncementId,
                                            announcement.getId())), announcement.getId()));
        }
        return annAndComsHashMap;
    }


}
